<!doctype html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>购物车</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Wx/css/base.css" />
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Wx/css/detail.css" />
</head>
<body>
<div class="detail" style="padding-top:50px; padding-bottom:100px;">
    <div id="header">
        <a href="javascript:history.go(-1);">返回</a>
        <div class="title">购物车（{$num_top}）</div>
        <span class="mange">管理</span>
    </div>
    <div class="cart">
        <div class="cancel"><span>删除产品</span></div>
        <volist name="wholesale" id="vo">
            <div class="cartlist">
                <div class="top02"><span class="select-all"><i class="selected"></i></span><b><img src="{$vo.g_u_id.avatar}"/></b><i>{$vo.g_u_id.nickname}</i><em>{$vo.g_u_id.farmers}</em></div>
                <ul>
                    <volist name="vo.commodity" id="pf">
                        <li  wid="{$pf.id}" gid="{$pf.store_info.id}" <neq name="pf.state" value="1"> <egt name="pf.state_order" value="0">class="selected onstate"</egt> </neq>>
                        <neq name="pf.state" value="1"><span class="select-icon"></span></neq>
                        <div class="pro">
                            <div class="pic" onclick="window.location.href='__MODULE__/Wholesale/prodetail/id/{$pf.g_id}'"><img src="<?=isMorePic($pf['store_info']['h_imgs'])?>"/></div>
                            <div class="name">
                                <h2>{$pf['store_info']['title']} {$pf['store_info']['u_num']}<?=getunit($pf['store_info']['unit'])?></h2>
                                <div class="price"><volist name="pf['price_range']" id="pr"><span><b>￥{$pr.price}</b><em>{$pr.start}-{$pr.end}件</em></span></volist></div>
                                <h3><span class="price02">￥<b>{$pf.price}</b></span><if condition="$pf['state'] eq 0"><em class="num"><span class="text_num"><lt name="pf.state_order" value="0">库存剩余{$pf.store_info.num}份</lt></span><s class="Subtract">-</s><b>{$pf.num}</b><s class="add">+</s></em><else /><em><input type="button" value="失效并删除" style="height: 25px;width: 90px;background: #F9790B;color:#ffffff;" onclick="unsetcart(this)"></em></if></h3>
                            </div>
                        </div>
                        </li>
                    </volist>
                </ul>
            </div>
        </volist>
    </div>
    <div class="submit">
        <div class="tongji">
            <div class="select-all"><span class="selected"></span>全选</div>
            <div class="total02"><i>应付金额:</i><span>￥<b></b><em></em><strong>（3%服务费）</strong></span></div>
        </div>
        <div class="ok">结算<!--(<b></b>)--></div>
    </div>
    <div class="notes">
        <div class="inner">
            <h2><img src="__PUBLIC__/Wx/img/del03.png"/></h2>
            <h3>删除成功！</h3>
        </div>
    </div>
    <!--<div class="notes02">-->
    <!--<div class="inner">-->
    <!--<h2><img src="__PUBLIC__/Wx/img/bj02.png"/></h2>-->
    <!--<h3>编辑成功！</h3>-->
    <!--</div>-->
    <!--</div>-->
    <div id="footer02">
        <a href="__MODULE__/Index/index">
            <div class="pic"><img src="__PUBLIC__/Wx/img/icon-index03.png"/></div>
            <div class="topic">首页</div>
        </a>
        <a href="__MODULE__/Wholesale/index">
            <div class="pic"><img src="__PUBLIC__/Wx/img/icon-buy.png"/></div>
            <div class="topic">我要进货</div>
        </a>
        <a href="javascript:0;" class="on">
            <div class="pic"><img src="__PUBLIC__/Wx/img/icon-cart02.png"/></div>
            <div class="topic">购物车</div>
        </a>
        <a href="__MODULE__/User/stores">
            <div class="pic"><img src="__PUBLIC__/Wx/img/icon-user.png"/></div>
            <div class="topic">门店中心</div>
        </a>
    </div>
</div>
<!--引用悬浮公共导航文件-->
<include file="Public:nav" />
<script  src="__PUBLIC__/Wx/js/jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">

    $(".click span").click(function(){
        if($(this).text() ==="导航"){
            $(this).text("收起");
            $('.link02').css('display','block')
        }else{
            $(this).text("导航");
            $('.link02').css('display','none')
        }//end if
    });//end fun

    $(document).ready(function(){
        price();//计算总价与总数
    });
    $(".mange").click(function(){
        if($(this).text() ==="管理"){
            $(this).text("完成");
            $("li").removeClass("selected");
            $(".select-all i").removeClass("selected");
            $(".tongji .select-all span").removeClass("selected");
            $(".cancel").css('display','block');
        }else{
            $(this).text("管理");
            $(".cancel").css('display','none');
            $("li").addClass("selected");
            $(".tongji .select-all span").addClass("selected");
            $(".select-all i").addClass("selected");
            price();//计算总价与总数
        }
    });//end fun

    $(".cancel").click(function(){
        var wid = new Array();
        $("li.selected.onstate").each(function(){
            wid.push($(this).attr('wid'));
        });//end each

        $.post("__MODULE__/Wholesale/editshopping",{'op':'delete','wid':wid},function (d) {
            if(d.state == 0){
                $("li.selected.onstate").remove();
                $(".cartlist .select-all i.selected").parents('.cartlist').remove();
            }//end if
            $(".notes").children("div.inner").children("h3").text(d.val);
            $('.notes').css("display",'block');
            $('.notes').delay(3000).hide(0);
        });//end post
        price();//计算总价与总数
    });//end fun

    $(".select-icon").click(function(){
        if($(this).parents("li").hasClass("selected")){
            $(this).parents("li").removeClass("selected");
            $(".tongji .select-all span").removeClass("selected");
            $(this).parents("li").parents("ul").siblings('.top02').children('span').children('i').removeClass("selected");
        }else{
            $(this).parents("li.onstate").addClass("selected");
        }//end if

        if($("li.onstate").length === $("li.selected.onstate").length){
            // $(this).parents("li").parents("ul").siblings('.top02').children('span').children('i').addClass("selected");
            $(".tongji .select-all span").addClass("selected");
        }else{
            $(".tongji .select-all span").removeClass("selected");
        }//end if

        if($(this).parents("ul").children("li.onstate").length ===$(this).parents("ul").children("li.selected.onstate").length){
            $(this).parents(".cartlist").find("i").addClass("selected");
        }else{
            $(this).parents(".cartlist").find('i').removeClass("selected");
        }//end if
        price();//计算总价与总数
    });//end fun

    $(".cartlist .select-all").click(function(){
        if($(this).find("i").hasClass("selected")){
            $(this).find("i").removeClass("selected");
            $(this).parents('.top02').siblings('ul').children('li').removeClass("selected");
            $(".tongji .select-all span").removeClass("selected");
        }else{
            $(this).find("i").addClass("selected");
            $(this).parents('.top02').siblings('ul').children('li.onstate').addClass("selected");

            if($(".cartlist").length == $('.top02').children('span').children('i.selected').length){
                $(".tongji .select-all span").addClass("selected");
            }//end if
        }//end if
        price();//计算总价与总数
    });//end fun

    $(".tongji .select-all").click(function(){
        if($(this).find("span").hasClass("selected")){
            $(this).find("span").removeClass("selected");
            $("li").removeClass("selected");
            $(".cartlist .select-all i").removeClass("selected");
        }else{
            $(this).find("span").addClass("selected");
            $("li.onstate").addClass("selected");
            $(".cartlist .select-all i").addClass("selected");
        }//end if
        price();//计算总价与总数
    });//end fun

    //增加份数
    $(".add").click(function(){
        var num = parseInt($(this).siblings("b").text());
        var li_obj = $(this).parents('li');
        var gid = li_obj.attr('gid');
        var wid = li_obj.attr('wid');
        var em_num = $(this);
        $.post('__MODULE__/Wholesale/editshopping',{'op':'edit','number':num,'gid':gid,'wid':wid,'sym':"1"},function (d) {
            if (d.state >0 && d.val){
                alert(d.val)
            }else{
                // alert(em_num.prev('b').text());
                if (d.state_order >=0){
                    li_obj.addClass('onstate');
                }//end if
                em_num.prev('b').text(d.num);
                em_num.parents('em.num').prev(".price02").children('b').text(d.price);
            }//end if
        });//end post
        price();//计算总价与总数
    });//end fun

    //减少份数
    $(".Subtract").click(function(){
        var num = parseInt($(this).siblings("b").text());
        var li_obj = $(this).parents('li');
        var span_obj = li_obj.children('div.pro').children('div.name').children('h3').children('em.num').children("span.text_num");//库存提示

        var gid = li_obj.attr('gid');
        var wid = li_obj.attr('wid');
        var em_num = $(this);
        $.post('__MODULE__/Wholesale/editshopping',{'op':'edit','number':num,'gid':gid,'wid':wid,'sym':"-1"},function (d) {
            if (d.state >0 && d.val){
                alert(d.val)
            }else{
                if (d.state_order >=0){
                    li_obj.addClass('onstate');
                    span_obj.empty();
                }//end if
                em_num.next('b').text(d.num);
                em_num.parents('em').prev("span").children('b').text(d.price);
            }//end if
        });//end post
        price();//计算总价与总数
    });//end fun

    function price(){  //计算总价与总数
        var wid = new Array();
        $("li.selected").each(function(){
            wid.push($(this).attr('wid'));
        });//end each

        $.post("__MODULE__/Wholesale/editshopping",{'op':'price','wid':wid},function (price) {
            $(".total02 b").text(price.all);
            if (price.all != 0){
                $(".total02 em").text('+'+price.charge);
            }else{
                $(".total02 em").text('');
            }//end if
        });//end post
        // $(".ok b").text(d.num);
    }//end fun

    function unsetcart(button) {
        var liobj = $(button).parents("li");
        var divonj = $(button).parents("div.cartlist");

        var wid = liobj.attr('wid');
        var li_num = divonj.children('ul').children('li').length;

        $.post("__MODULE__/Wholesale/editshopping",{'op':'delete','wid':wid},function (d) {
            if(d.state == 0){
                liobj.remove();
                if (li_num == 1){
                    divonj.remove();
                }//end if
            }//end if
            $(".notes").children("div.inner").children("h3").text(d.val);
            $('.notes').css("display",'block');
            $('.notes').delay(3000).hide(0);
        });//end post
        price();//计算总价与总数
    }//end fun

    $(".submit .ok").click(function(){
        var wid = '';
        $("li.selected").each(function(){
            wid += $(this).attr('wid')+',';
        });//end each
        wid = wid.replace(/,,/g,",");//去重
        wid = wid.substring(0,wid.length-1);//去尾
        window.location.href="__MODULE__/Wholesale/Payment/wid/"+wid;

    })//end fun
</script>

</body>
</html>